import java.io.File;
import java.io.IOException;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;

import com.wcohen.ss.expt.MatchData;

public class MatchReader {

	public MatchData readFile() throws IOException{
        JOptionPane.showMessageDialog(null,"Please select the data to be matched");
        JFileChooser fileChooser = new JFileChooser();
        fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        fileChooser.setMultiSelectionEnabled(false);
        fileChooser.setCurrentDirectory(new File("D:\\School\\Bachelor Thesis\\Data"));
        int returnVal = fileChooser.showOpenDialog(null);
        MatchData data;

        if (returnVal == JFileChooser.APPROVE_OPTION){
        	File file = fileChooser.getSelectedFile();
        	data = new MatchData(file.toString());
        	return data;
        } 
        else if (returnVal == JFileChooser.CANCEL_OPTION || returnVal == JFileChooser.ERROR_OPTION) {
        	System.exit(0);
        }
        return null;
    }
	
	public MatchData[] readAllFiles() throws IOException{
		JOptionPane.showMessageDialog(null,"Please select the data to be matched");
        JFileChooser fileChooser = new JFileChooser();
        fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        fileChooser.setMultiSelectionEnabled(false);
        fileChooser.setCurrentDirectory(new File("D:\\School\\Bachelor Thesis\\Data"));
        int returnVal = fileChooser.showOpenDialog(null);

        if (returnVal == JFileChooser.APPROVE_OPTION){
        	File file = fileChooser.getSelectedFile();
        	File[] listOfFiles = file.listFiles();
        	MatchData[] data = new MatchData[listOfFiles.length];
        	for(int i = 0; i < listOfFiles.length; i++){
        		File temp = listOfFiles[i];
        		data[i] = new MatchData(temp.toString());
        	}
        	return data;
        } 
        else if (returnVal == JFileChooser.CANCEL_OPTION || returnVal == JFileChooser.ERROR_OPTION) {
        	System.exit(0);
        }
        return null;
	}
}
